package com.santiao.youxiang.ui.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import com.gyf.immersionbar.ImmersionBar
import com.santiao.publics.ui.SettingFragment
//import com.lazyliuzy.commonui.utils.lzy.LZYADSUtils
import kotlin.apply
//import kotlin.jvm.java

import com.santiao.youxiang.databinding.ActivityHabitTimeLineBinding

import com.santiao.youxiang.ui.adapter.TimeLineAdapter
import com.santiao.youxiang.ui.fragment.HomeViewModel
import kotlin.getValue

class TimeLineActivity: AppCompatActivity() {
    private lateinit var binding: ActivityHabitTimeLineBinding
//    private lateinit var lzyadsUtils: com.lazyliuzy.commonui.utils.lzy.LZYADSUtils
var type_a="" //1 医保 2：社保

    var slePosition=1

    private val HviewModel: HomeViewModel by viewModels()

    lateinit var Tadapter : TimeLineAdapter

    var struri=""
    // 在类顶部定义
    val REQUEST_STORAGE_PERMISSION = 1001  // 可以是任意唯一整数

    companion object {
        // 定义一个静态方法来创建Intent
        // 定义一个静态方法来创建Intent并携带uri数据
        fun startActivity(context: Context?/*, type: String*/) {

            val intent = Intent(context, TimeLineActivity::class.java).apply {

//                putExtra("type", type)

            }

            context!!.startActivity(intent)
        }

    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityHabitTimeLineBinding.inflate(layoutInflater)
        setContentView(binding?.root)
//        type_a= intent.getStringExtra("type").toString()
        ImmersionBar.with(this)
            .transparentStatusBar()
            .statusBarDarkFont(true)
            .transparentNavigationBar()
            .init()
        initViews(type_a)
        SettingFragment.adLoad2(0,null,binding.flContent22,this,this);
    }



     fun initViews(type: String) {
//        initad()

         initclick()
         initRv()
         initdata()

        binding.ivBack.setOnClickListener { onBackPressed() }





    }

    fun initclick(){

//        binding.llQq.thrillClickListener {
//            AddAccountActivity.startActivity(this,"1")
//        }
//
//        binding.llE163.thrillClickListener {
//            AddAccountActivity.startActivity(this,"2")
//        }
//
//        binding.llE126.thrillClickListener {
//            AddAccountActivity.startActivity(this,"3")
//        }




    }

    fun switchItem(position: Int) {

    }


    fun initRv(){


        Tadapter= TimeLineAdapter()


        val layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
        Log.e("initrv: ", "2")
//        Camadapter

        binding!!.rvHabitTime?.layoutManager = layoutManager
        binding!!.rvHabitTime?.adapter = Tadapter

//        Tadapter?.setOnItemClickListener { adapter, view, position ->
//
////            val item = adapter.data[position] as HomeCamBean  // 明确类型
////            val userId = item.userId.toString()
////            val chanelId = item.channelID.toString()
////            val token = item.token.toString()
//
//
////            var userIds= adapter.data.get(0)
//
//
//
//
//
////            val cam = LitePal.where("userId = ? ", userId).findFirst(liveCam::class.java)
//
//
//
//        }

//        Tadapter!!.setOnItemChildClickListener { _, view, position ->
//
//
//
//            if (view.id == R.id.ll_del) {
//                // 删除逻辑
//                delFromdb(Hadapter!!.data.get(position).id.toString())
//                Hadapter!!.removeAt(position)
//                Hadapter!!.notifyItemRemoved(position)
//
//            }
//
//            if (view.id == R.id.ll_edit) {
//                // 编辑逻辑
////                delFromdb(billadapter!!.data.get(position).id.toString())
////                billadapter!!.removeAt(position)
////                billadapter!!.notifyItemRemoved(position)
//                HabitEditActivity.startActivity(requireContext(),"2",Hadapter!!.data.get(position).id.toString())
//
//            }
//
////            val bundle=Bundle()
////            bundle.putInt("type", type)
////            bundle.putSerializable("email", itemData)
////            LZYBaseActivity.forward<EmailDetailActivity>(mContext,bundle)
//
//        }


    }

    fun initdata(){
        HviewModel.getDBLine()
//        HviewModel.getDBHabit()

        HviewModel.lineData.observe(this) { list ->
            Log.e("initdata: ",list.toString() )
            Tadapter.data.clear()
            Tadapter.setList(list)
        }
    }

    fun   initad() {
//        myContext = requireContext()
//        lzyadsUtils=
//            com.lazyliuzy.commonui.utils.lzy.LZYADSUtils("Task1Activity", this@Task1Activity)
//        com.lazyliuzy.commonui.utils.lzy.LZYADSUtils.loadSimpleAd1(com.lazyliuzy.commonui.databinding.ActivityTask1Binding.flAd)
//        com.lazyliuzy.commonui.utils.lzy.LZYADSUtils.showAdCpTurn()



    }

}